var title = "sdfs";

$( function(){
	//导航栏样式改变
	$( '.main-top li' ).on( 'click', function(){
		$( '.main-top li' ).removeClass( 'active' );
		$( this ).addClass( 'active' );
		var index = $( this ).index();

		//变速滚动
		var targetScroll = $( '.title_content:eq(' + index + ')' ).offset().top - 50;
		if( $( '.main-top' ).css( 'position' ) == 'relative' && $( document ).scrollTop() < targetScroll ){
			targetScroll -= 50;
		}
		var acceleration = 3;	//加速度
		window.clearInterval( timer ); 
		var timer = window.setInterval( function(){
			var currentScroll = $( document ).scrollTop();
			if( currentScroll == targetScroll ){
				window.clearInterval( timer );
			}
			window.setTimeout( function(){
				if( currentScroll != $( document ).scrollTop() ){
					window.clearInterval( timer );
				}
			}, 200);
			if( currentScroll > targetScroll ){
				var speed = Math.ceil( ( currentScroll - targetScroll ) / acceleration );
				if( speed <= acceleration ){
					$( document ).scrollTop( targetScroll );
				}else{
					$( document ).scrollTop( currentScroll - speed );
				}
			}else if( currentScroll < targetScroll ){
				var speed = Math.ceil( ( targetScroll - currentScroll ) / acceleration );
				if( speed <= acceleration ){
					$( document ).scrollTop( targetScroll );
				}else{
					$( document ).scrollTop( currentScroll + speed );
				}
			}
		}, 20);
	})
	
	//滚动时改变导航栏对应可视内容的链接按钮的样式
	$(window).scroll(function() {
		var scrollTop = $(window).scrollTop();
		for( var i=0; i<$( '.title_content' ).length; i++ ){
			var offsetTop = $( '.title_content:eq(' + i + ')' ).offset().top;
			var temp = offsetTop - scrollTop;
			if( temp >= 0 && temp <= 430 ){
				$( '.main-top li' ).removeClass( 'active' );
				$( '.main-top li:eq(' + i + ')' ).addClass( 'active' );
			}
		}
	});
	
	//固定导航栏于顶部
	var offsetTop = $( '.main-top' ).offset().top;
	$( document ).scroll( function(){
		var scollTop = $( this ).scrollTop();
		if( scollTop >= offsetTop ){
			$( '.main-top' ).css( {
				"position": "fixed",
        		"top": 0,
        		"left": 0,
        		"background-color": "rgba( 243, 248, 251, 0.8 )"
			})
		}else{
			$( '.main-top' ).css( {
				"position": "",
        		"top": "",
        		"left": "",
        		"background-color": ""
			})
		}
	})
	
	//更多页跳转
	$( '.more_footer a' ).on( 'click', function(){
		var sczrType = Number( $( this ).attr( 'sczrType' ) );
		var linkName = "";
		switch( sczrType ){
			case 0: linkName = "djxx"; break;
			case 1: linkName = "xkxx"; break;
			case 2: linkName = "rzxx"; break;
			case 3: linkName = "bzzl"; break;
			case 4: linkName = "pjpc"; break;
			case 5: linkName = "dbdy"; break;
			default: linkName = "djxx";
		}
		window.location.href = '/sczr/' + linkName;
	});

})
